<%@ page language="java" contentType="text/html; charset=UTF-8" import="java.util.*,
com.brother.model.*,com.ibatis.common.util.*"   pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ include file="international.jsp" %> 
<jsp:useBean id="trackerService" class="com.brother.service.TrackerService"></jsp:useBean>

<%
com.brother.model.Customer c = (com.brother.model.Customer)session.getAttribute(com.brother.Constants.LOGIN_SESSTION_NAME);
if(c == null || c.getUserid() == 0){
	out.println("top.location.href='login.jsp'");
	return;
}

%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title><fmt:message key="manage.title.product"/> - <fmt:message key="company.name"/></title>
<link rel="stylesheet" type="text/css"  href="style.css" />
<link rel="stylesheet" type="text/css" href="css/ext-all.css" />
<link rel="stylesheet" type="text/css" href="css/grid-examples.css" />
<style type="text/css">
.whitebg{
	background-color: #ffffff;
}
body{
background-color: #ffffff;
}
</style>

    <script type="text/javascript" src="js/ext-base.js"></script>
    <script type="text/javascript" src="js/ext-all.js"></script>
    <script type="text/javascript" src="js/search.js"></script>
    <script type="text/javascript" src="js/trackerList.js"></script>
    <script type="text/javascript" src="./js/common.js"></script>
    
</head>
<body style=" min-height:100%;">

<div id="msg" name="msg" style="background-color:#D4DF55; position:absolute; z-index:11; left: 10px; top: 61px; display:inline"></div>
<script>
var waitingMsg = '<fmt:message key="waiting.msg"/>';
var waitingProgressText = '<fmt:message key="waiting.loading"/>';
       function Point(iX, iY){ 
          this.x = iX; 
          this.y = iY; 
       } 
 function fGetXY(obj){ 
           var oTmp = obj;     
           if(!oTmp||(typeof(oTmp.offsetLeft) == "undefined") 
               ||(typeof(oTmp.offsetTop) == "undefined") 
               ||!oTmp.tagName){ 
                return null; 
           } 
           var pt = new Point(0,0);   
           do{ 
      pt.x += oTmp.offsetLeft; 
      pt.y += oTmp.offsetTop; 
      //alert(oTmp.parentNode.tagName);
      oTmp = oTmp.parentNode; 
  } while(oTmp.tagName!="BODY"); 
  return pt; 
       } 
       
	   var gMsgTop = 0; //fGetXY(document.getElementById("tmp_pos")).y;
function show_tip(msg)
{
	if (gMsgTop == 0)
	{
		gMsgTop = fGetXY(document.getElementById("tmp_pos")).y + 5;
		document.getElementById("msg").style.top = gMsgTop;
		document.getElementById("msg").style.display = "inline";
		// alert(document.getElementById("msg").style.offsetTop);
	}
	
	document.getElementById("msg").innerHTML = msg;
}

function del_product(id, uin)
{
	
	if ("demo" == "<%=c.getName()%>")
	{
		//alert("<fmt:message key="manage.delete.demo.tip"/>");
		Ext.MessageBox.alert('',"<fmt:message key="manage.delete.demo.tip"/>");
		return;
	}

	//var trackerIds = document.getElementsByName("trackerId");
var datas =manageTrackersGrid.getSelectionModel().getSelections();
	var url = "gps_product.jsp?action=del";
	
	for(var i = 0; i < datas.length; i++){
		//if(trackerIds[i].checked)
		url = url + '&trackerid='+datas[i].data.trackerid;
	}
	
	//console.log(datas, url);
	
	if(url.indexOf("trackerid") == -1){
		//alert('<fmt:message key="manage.delete.tip"/>');
		Ext.MessageBox.alert('','<fmt:message key="manage.delete.no.data.select"/>');
		return;
	}
//confirm('fsdfdf df');

	Ext.MessageBox.confirm('', '<fmt:message key="manage.delete.tip"/>', function(btn){
		if(btn == 'yes'){
			window.location.href=url;
		}
	});
	
	return;
}

var mutilpleSelectError = '<fmt:message key="manage.tracker.choose.only.one"/>';
var pleaseChooseTracker = '<fmt:message key="manage.tracker.choose"/>';

function onModify(){


	var trackerIds = document.getElementsByName("trackerId");

	var datas =manageTrackersGrid.getSelectionModel().getSelections();
	
	var url = "gps_editproduct.jsp?carModelId=";
	var selected = false;
	//for(var i = 0; i < trackerIds.length; i++){
		if(datas.length == 1){
			url = url + '&trackerid='+datas[0].data.trackerid;
			selected = true;
		}else if(datas.length > 1){
			//alert(mutilpleSelectError);
			Ext.MessageBox.alert('',mutilpleSelectError);
			return;
		}
		
	//}
	if(!selected){
	 	//alert(pleaseChooseTracker);
	 	Ext.MessageBox.alert('',pleaseChooseTracker);
		return;
	}
	window.location.href=url;
}

var userNameTitle = '<fmt:message key="user.name"/>';
var trackerNameTitle = '<fmt:message key="tracker.name"/>';
var imeiTitle = '<fmt:message key="tracker.id"/>';
var remarkTitle = '<fmt:message key="tracker.remark"/>';
var displayMsg = '<fmt:message key="tracker.list.display.msg"/>';
var emptyMsg = '<fmt:message key="tracker.list.empty.msg"/>';

var search_select_user='<fmt:message key="search.select.user"/>';
var search_select_tracker='<fmt:message key="search.select.tracker"/>';
var beforePageText = '<fmt:message key="beforePageText"/>';
var refreshText = '<fmt:message key="grid.refreshText"/>';
var afterPageText = '<fmt:message key="afterPageText"/>';

Ext.onReady(function(){
	Ext.MessageBox.buttonText.yes = '<fmt:message key="button.yes.text"/>';
	Ext.MessageBox.buttonText.no = '<fmt:message key="button.no.text"/>';
	Ext.MessageBox.buttonText.cancel = '<fmt:message key="button.cancel.text"/>';
	
	top.ajustProducts('<fmt:message key="tracker.info"/>', 850, 550);
});

</script>

<table id="container" width="100%" height="100%" style="min-height:100%; height:100%; " border="0" cellpadding="0" cellspacing="0">

<tr valign="top" style="height:100%">
	<td height="100%" align="left" style="padding-left:8px; padding-right:8px; min-height:100%">


			<table width="100%" align="left">
				<tr>
					<td width="210">
					<table class="tableNoBorder" >
					<tr>
					<td><div id="addbtn"></div></td>
					<td><div id="delbtn"></div></td>
					<td><div id="modifybtn"></div></td>
					<td><div id="exportbtn"></div></td></tr></table>
					<script type="text/javascript">
						Ext.onReady(function(){
							
						var button = new Ext.Button({renderTo:'addbtn',type:'button', 
							text:'<fmt:message key="manage.add"/>',split: true,width:80,
							enableToggle:false});
						button.on('click',function(){
							window.location.href = 'gps_editproduct.jsp';
							});
						button = new Ext.Button({renderTo:'delbtn',type:'button', 
							text:'<fmt:message key="manage.delete"/>',split: true,width:80,
							enableToggle:false});
						button.on('click',function(){
							del_product();
							});
						button = new Ext.Button({renderTo:'modifybtn',type:'button', 
							text:'<fmt:message key="manage.modify"/>',split: true,width:80,
							enableToggle:false});
						button.on('click',function(){
							onModify();
							});

						button = new Ext.Button({renderTo:'exportbtn',type:'button', 
							text:'<fmt:message key="report.export.excel"/>',split: true,width:80,
							enableToggle:false});
						button.on('click',function(){
							searchTrackers(true);
							});
						
							});
					</script>
										
					</td>
					<td>					<form id="searchForm" action="gps_product.jsp" method="post">
					<input type="hidden" value="search" name="action"/>
					<table class="tableNoBorder" ><tr>
					<td><input type="text" name="userName" value="" id="userAutocomplete" style="width:100px"/></td>
					<td><input type="text" name="trackerName" value=""  id="trackersAutocomplete" style="width:100px"/></td>
					
					<td id="searchBtn"><script type="text/javascript">
						Ext.onReady(function(){
						var button = new Ext.Button({renderTo:'searchBtn',type:'button', 
							text:'<fmt:message key="manage.search"/>',split: true,width:120,
							enableToggle:false});
						button.on('click',function(){
							searchTrackers();
							});
							});
					</script></td>
					</tr>
					</table>
					</form></td>
				</tr>
								
				<tr>
					<td colspan="2" width="100%" id="grid-container">
												
				
					</td>
				</tr>
			</table>

	</td>
</tr>


</table>
</body>
</html>
<%
com.brother.database.DataBase.closeThreadConnection();
%>